package cn.zwx.common.rocket.producer.runner;

import cn.zwx.common.rocket.consumer.bo.SubscribeBO;
import cn.zwx.common.rocket.consumer.service.MqConsumerService;
import cn.zwx.common.rocket.producer.listener.DefaultConsumerListener;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Component
public class ConsumerRunner implements CommandLineRunner {

    @Resource
    MqConsumerService mqConsumerService;
    @Override
    public void run(String... args) throws Exception {
        DefaultConsumerListener defaultConsumerListener = new DefaultConsumerListener();
        List<SubscribeBO> boList = new ArrayList<>();
        // 普通消息
        SubscribeBO defaultMsg = new SubscribeBO();
        defaultMsg.setTopic("user_default_topic");
        defaultMsg.setTag("*");
        boList.add(defaultMsg);
        // 延迟消息
        SubscribeBO deliverTimeMsg = new SubscribeBO();
        deliverTimeMsg.setTopic("user_delay_topic");
        deliverTimeMsg.setTag("*");
        boList.add(deliverTimeMsg);
        // 事务消息
        SubscribeBO transMsg = new SubscribeBO();
        transMsg.setTopic("user_trans_topic");
        transMsg.setTag("*");
        boList.add(transMsg);
        mqConsumerService.subscribeForDefault(boList,defaultConsumerListener);
        List<SubscribeBO> orderBoList = new ArrayList<>();
        SubscribeBO orderMsg = new SubscribeBO();
        orderMsg.setTag("*");
        orderMsg.setTopic("user_order_topic");
        orderBoList.add(orderMsg);
        // 顺序消息
        mqConsumerService.subscribeForOrder(orderBoList,defaultConsumerListener);
    }
}
